package Tree;

public class treeTest {
    public static void main(String[] args) {
        Integer[] pre = {8,3,1,null,null,6,4,null,null,7,null,null,10,null,14,13,null,null,null};
        BinaryTree<Integer> eBinaryTree = new BinaryTree<>(pre);

        System.out.print("使用前序遍历得到结果为");
        eBinaryTree.preorder();
        eBinaryTree.preorderTraverse();
        System.out.println("------------------------------------------------------------------------------------------------------------");

        System.out.println("判断该二叉树是否是一棵二叉排序树："+(eBinaryTree.isSorted()?"该树为一棵排序二叉树":"该树不为一棵排序二叉树"));
        System.out.println("------------------------------------------------------------------------------------------------------------");

        System.out.println("检验二叉树性质3——叶子节点的个数为2度节点数的个数加1");
        BinaryTrees.property3(eBinaryTree);
        System.out.println("------------------------------------------------------------------------------------------------------------");

        eBinaryTree.remove(14);
        System.out.print("使用 remove 方法移除值为 14 节点后得到的二叉树为:");
        eBinaryTree.preorder();
        System.out.println("------------------------------------------------------------------------------------------------------------");

        System.out.println("值为6的结点的父母结点为结点值为"+eBinaryTree.parent(6).data+"的结点");
        System.out.println("------------------------------------------------------------------------------------------------------------");

        BinaryTree<Integer> preBinaryTree = new BinaryTree<>(pre);
        System.out.print("使用前序顺序交换左右节点前的preBinaryTree为：");
        preBinaryTree.preorder();
        BinaryTrees.preSwap(preBinaryTree);
        System.out.print("使用前序顺序交换左右节点后的preBinaryTree为：");
        preBinaryTree.preorder();
        System.out.println("------------------------------------------------------------------------------------------------------------");

        BinaryTree<Integer> inBinaryTree = new BinaryTree<>(pre);
        System.out.print("使用中序顺序交换左右节点前的inBinaryTree为：");
        inBinaryTree.preorder();
        BinaryTrees.inSwap(inBinaryTree);
        System.out.print("使用中序顺序交换左右节点后的inBinaryTree为：");
        inBinaryTree.preorder();
        System.out.println("------------------------------------------------------------------------------------------------------------");

        BinaryTree<Integer> postBinaryTree = new BinaryTree<>(pre);
        System.out.print("使用后序顺序交换左右节点前的postBinaryTree为：");
        postBinaryTree.preorder();
        BinaryTrees.postSwap(postBinaryTree);
        System.out.print("使用后序顺序交换左右节点后的postBinaryTree为：");
        postBinaryTree.preorder();
    }
}
